﻿using System;
using System.IO;

namespace _04.TextFileCompare
{
    class TextFileCompare
    {
        static void CreateFileWithNumberRange(int start, int end, string fileName)
        {
            if (start > end)
            {
                var temp = start;
                start = end;
                end = temp;
            }

            StreamWriter streamWriter = new StreamWriter(fileName);
            using (streamWriter)
            {
                for (int i = start; i <= end; i++)
                {
                    streamWriter.WriteLine(i);
                }
            }
        }

        static void RemoveRandonLines(string inputFileName, string outputFileName)
        {
            Random randomNumber = new Random();
            using (StreamReader sr = new StreamReader(inputFileName))
            using (StreamWriter sw = new StreamWriter(outputFileName))
            {
                string line = sr.ReadLine();
                while (line != null)
                {
                    if (randomNumber.Next()%2 == 0)
                    {
                       sw.WriteLine("");
                    }
                    else
                    {
                        sw.WriteLine(line);
                    }
                    line = sr.ReadLine();
                }
            }
        }

        static void Main()
        {
            string textFile1 = "Text1.txt";
            string textFile2 = "Text2.txt";
            CreateFileWithNumberRange(0, 100, textFile1);
            RemoveRandonLines(textFile1, textFile2);
            int sameLineCounter = 0;
            int differentLineCounter = 0;
            
            using (StreamReader file1 = new StreamReader(textFile1))
            using (StreamReader file2 = new StreamReader(textFile2))
            {
                string lineFile1 = file1.ReadLine();
                string lineFile2 = file2.ReadLine();
                while (lineFile1 != null)
                {
                    if (lineFile1 == lineFile2)
                    {
                        sameLineCounter++;
                    }
                    else
                    {
                        differentLineCounter++;
                    }
                    lineFile1 = file1.ReadLine();
                    lineFile2 = file2.ReadLine();
                }
            }
            Console.WriteLine("Same lines are: {0},\nDifferent lines are: {1}", sameLineCounter, differentLineCounter);
        }
    }
}
